home *** CD-ROM | disk | FTP | other *** search
/ Enter 2005 October / enter-2005-10.iso / files / jedit42install.exe / {app} / macros / Editing / Move_Line_Up.bsh < prev   
Encoding:
Text File  |  2004-08-29  |  2.2 KB  |  70 lines

  1. /*
  2.  * Move_Line_Up.bsh - a BeanShell macro for moving lines up.
  3.  *
  4.  * Copyright (C) 2004 Nicholas O'Leary nol@deferential.net
  5.  * 
  6.  * :mode=beanshell:tabSize=3:indentSize=3:maxLineLen=0:noTabs=true:
  7.  * :indentOnTab=true:indentOnEnter=true:folding=explicit:collapseFolds=1:
  8.  *
  9.  * {{{ License
  10.  * This program is free software; you can redistribute it and/or
  11.  * modify it under the terms of the GNU General Public License
  12.  * as published by the Free Software Foundation; either version 2
  13.  * of the License, or any later version.
  14.  *
  15.  * This program is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  * GNU General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with the jEdit program; if not, write to the Free Software
  22.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  23.  * }}}
  24.  *
  25.  *  
  26.  * Changes:
  27.  *  05-Jul-04: Initial Implementation
  28.  *
  29.  * $Id: Move_Line_Up.bsh,v 1.1 2004/07/06 00:14:58 spestov Exp $
  30.  */
  31.  
  32. // Get the current line
  33. int lineNo = textArea.getCaretLine();
  34.  
  35. // Make sure we are allowed to edit the buffer, and that we're not at the start
  36. if (!buffer.isEditable() || lineNo == 0) {
  37.    textArea.getToolkit().beep();
  38.    return 1;
  39. }
  40. // Start the edit
  41. buffer.beginCompoundEdit();
  42. // Get the caret position on the line
  43. int lineCaretOffset = textArea.getCaretPosition()-buffer.getLineStartOffset(lineNo);
  44. // Get the line text to move
  45. String line = buffer.getLineText(lineNo);
  46. // Remove the line
  47. textArea.deleteLine();
  48. // Get the position to insert the line at
  49. int newLinePos = buffer.getLineStartOffset(lineNo-1);
  50. // Inser the line
  51. buffer.insert(newLinePos,line+"\n");
  52. // Move the cursor into the same position on the new line
  53. textArea.setCaretPosition(newLinePos+lineCaretOffset);
  54. // Indent this line
  55. buffer.indentLine(lineNo-1,true);
  56. // End the edit
  57. buffer.endCompoundEdit();
  58.  
  59. /*
  60.  
  61. Macro index data (in DocBook format)
  62.  
  63.    <listitem>
  64.       <para><filename>Move_Line_Up.bsh</filename></para>
  65.       <abstract><para>Moves the current line up one, with automatic 
  66.       indentation.</para></abstract>   
  67.       </listitem>
  68.  
  69. */
  70.